<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>平台管理</title>
    <link rel="stylesheet" type="text/css" href="../css/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../css/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="../css/themes/color.css">
    <link rel="stylesheet" type="text/css" href="../css/style.css">
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../js/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="../js/config.js"></script>
</head>
<body>
<table id="dg" title="" class="easyui-datagrid" fit="true" multiSort="true"
       toolbar="#query" footer="#toolbar" pagination="true" rownumbers="true" fitColumns="true" singleSelect="true">
    <thead>
    <tr>
        <th field="platformCode" sortable="true" width="50">平台编码</th>
        <th field="platformName" sortable="true" width="50">平台名称</th>
        <th field="description" sortable="true" width="50">描述</th>
        <th field="createUser" sortable="true" width="50">创建人</th>
        <th field="createTime" sortable="true" width="50" formatter="CommonUtil.dateFormatter">创建时间</th>
        <th field="updateUser" sortable="true" width="50">修改人</th>
        <th field="updateTime" sortable="true" width="50" formatter="CommonUtil.dateFormatter">修改时间</th>
    </tr>
    </thead>
</table>
<div id="query" style="padding:2px 5px;">
    平台编码:<input id="qPlatformCode" class="easyui-textbox" style="width:110px"/>
    平台名称:<input id="qPlatformName" class="easyui-textbox" style="width:110px"/>
    <a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="Platform.loadData()">查询</a>
</div>
<div id="toolbar">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true"
       onclick="Platform.newPlatform()">新增</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true"
       onclick="Platform.editPlatform()">修改</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true"
       onclick="Platform.deletePlatform()">删除</a>
</div>

<div id="dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
     closed="true" buttons="#dlg-buttons">
    <div class="ftitle">平台信息</div>
    <form id="fm" class="form" method="post" novalidate>
        <div class="fitem">
            <label>编码:</label>
            <input id="platformCode" name="platformCode" class="easyui-textbox" required="true"/>
        </div>
        <div class="fitem">
            <label>名称:</label>
            <input id="platformName" name="platformName" class="easyui-textbox" required="true"/>
        </div>
        <div class="fitem">
            <label>描述:</label>
            <input id="description" name="description" class="easyui-textbox" data-options="multiline:true"
                   style="height:50px"/>
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="Platform.savePlatform()"
       style="width:90px">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel"
       onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
</div>
<script type="text/javascript">
    $(function () {
        Platform.loadData();
    });

    window.Platform = {
        id: 0,
        loadData: function () {
            $('#dg').datagrid({
                method: 'GET',
                url: window.BASEPATH + 'platform',
                queryParams: {
                    platformCode: $("#qPlatformCode").val(),
                    platformName: $("#qPlatformName").val()
                },
                loadFilter: function (data) {
                    if (data.suc == true) {
                        return data.result;
                    } else {
                        return null;
                    }
                }
            });
        },
        newPlatform: function () {
            $('#dlg').dialog('open').dialog('center').dialog('setTitle', '新增');
            $('#fm').form('clear');
            Platform.id = 0;
        },
        editPlatform: function () {
            var row = $('#dg').datagrid('getSelected');
            if (row) {
                $('#dlg').dialog('open').dialog('center').dialog('setTitle', '修改');
                $('#fm').form('load', row);
                Platform.id = row.id;
            }
        },
        savePlatform: function () {
            var model = {
                platformCode: $("#platformCode").val(),
                platformName: $("#platformName").val(),
                description: $("#description").val()
            }
            if (Platform.id == 0) {
                //新增
                $.ajax({
                    type: "POST",
                    url: window.BASEPATH + 'platform',
                    contentType: "application/json;charset=UTF-8",
                    dataType: "json",
                    data: JSON.stringify(model),
                    success: function (data, textStatus, jqXHR) {
                        if (data.suc) {
                            $('#dlg').dialog('close');
                            $('#dg').datagrid('reload');
                        } else {
                            $.messager.show({
                                title: 'Error',
                                msg: data.message
                            });
                        }
                    }
                });
            } else {
                //修改
                var row = $('#dg').datagrid('getSelected');
                $.ajax({
                    type: "PUT",
                    url: window.BASEPATH + 'platform/' + row.id,
                    contentType: "application/json;charset=UTF-8",
                    dataType: "json",
                    data: JSON.stringify(model),
                    success: function (data, textStatus, jqXHR) {
                        if (data.suc) {
                            $('#dlg').dialog('close');
                            $('#dg').datagrid('reload');
                        } else {
                            $.messager.show({
                                title: 'Error',
                                msg: data.message
                            });
                        }
                    }
                });
            }
        },
        deletePlatform: function () {
            var row = $('#dg').datagrid('getSelected');
            if (row) {
                $.messager.confirm('Confirm', '确定删除?', function (r) {
                    if (r) {
                        $.ajax({
                            type: "DELETE",
                            url: window.BASEPATH + 'platform/' + row.id,
                            dataType: "json",
                            success: function (data, textStatus, jqXHR) {
                                if (data.suc) {
                                    $('#dg').datagrid('reload');
                                } else {
                                    $.messager.show({
                                        title: 'Error',
                                        msg: data.message
                                    });
                                }
                            }
                        });
                    }
                });
            }
        }
    }
</script>
</body>
</html>